<?php
/**
 * FastApp.
 * 9/25/24
 * @Author deepsea159
 * @Contact telegram:deepsea159
 */

namespace App\Game\Api\Service;

use App\Fastapp\Api\Service\BaseService;
use App\Fastapp\Model\AccountInviteLevel;
use App\Fastapp\Model\AccountRecharge;
use App\Game\Model\GameBet;

class AccountService extends BaseService
{
    public static function effectiveLevel(int $user_id, int $account_type): void
    {
        $query = AccountInviteLevel::query()->where(['user_id' => $user_id]);
        if (!$query->value('status')) {
            $setting = api_cache()->getAppSetting($account_type);
            $recharge_amount = AccountRecharge::query()->where(['user_id' => $user_id, 'status' => 1])->sum('amount');
            $bet_amount = GameBet::query()->where(['user_id' => $user_id, 'status' => 3])->sum('result_amount');
            if ($recharge_amount > $setting['open_box_recharge'] && $bet_amount > $setting['open_box_bet']) {
                $query->update(['status' => 1]);
            }
        }
    }
}